package com.hhkj.study.admin.article.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.hhkj.study.admin.article.entity.Article;
import com.hhkj.study.admin.article.model.req.ArticleReq;
import com.hhkj.study.admin.article.model.res.ArticleRes;
import com.hhkj.study.admin.article.service.biz.ArticleBizService;
import com.ruoyi.common.annotation.PermissionPrefix;
import com.ruoyi.common.base.biz.controller.v3.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.valid.VDisable;
import com.ruoyi.common.valid.VEdit;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* ArticleController
*
* @author SERVER
* @since 2024-09-06
*/
@RestController
@PermissionPrefix("article:article")
@RequestMapping("/admin/article")
public class ArticleController extends BaseController<Article, ArticleReq, ArticleRes, ArticleBizService> {

    /** 上下架 */
    @PreAuthorize("@ss.hasPermi(this, 'edit')")
    @PutMapping("/publish")
    public AjaxResult updatePublishFlag(@Validated(value = {VDisable.class, VEdit.class}) @RequestBody ArticleReq req) {
        return toAjax(this.getBizService().updatePublishFlag(req));
    }

    /** 标记/取消重点资讯 */
    @PreAuthorize("@ss.hasPermi(this, 'edit')")
    @PutMapping("/mark/{idList}")
    public AjaxResult markArticle(@PathVariable List<Long> idList) {
        CollectionUtil.removeNull(idList);
        return toAjax(this.getBizService().markArticle(idList));
    }
}
